package org.ala.tiktools_clickhouse_generator.conn;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import com.clickhouse.jdbc.ClickHouseDataSource;

/**
 *
 *	@author ala
 *	@date 2025年6月5日
 */
@SuppressWarnings("deprecation")
public class ConnectionHolder {

	
	/**
	 * 	连接属性
	 */
	protected String url, username, password;
	/**
	 * 	连接
	 */
	protected Connection conn;
	

	public ConnectionHolder(String url, String username, String password) throws SQLException {
		this.url = url;
		this.username = username;
		this.password = password;
		
		Properties props = new Properties();
		props.setProperty("user", username);
		props.setProperty("password", password);
		ClickHouseDataSource ds = new ClickHouseDataSource(url, props);
		conn = ds.getConnection();
	}
	
	
	/**
	 * 	获取连接
	 */
	public Connection getConnection() {
		return conn;
	}
}
